package cn.easyar.samples.helloarqrcode;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import cn.easyar.samples.helloarqrcode.xunfei.VoiceBean;
import cn.easyar.samples.helloarqrcode.xunfei.VoiceOrder;


public class WarnActivity extends Activity {
    private Button btn_back;
    private TextView tv_toolbar_center;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去除title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //去掉Activity上面的状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_warn);
        EventBus.getDefault().register(this);
        VoiceOrder.activityList.add("WarnActivity");
        tv_toolbar_center = (TextView) findViewById(R.id.tv_toolbar_center);
        btn_back = (Button) findViewById(R.id.btn_back);
        tv_toolbar_center.setText("警告页面");
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void voiceEvent(VoiceBean voiceBean) {
        if(voiceBean.str.contains(VoiceOrder.VOICE_QUIT)&&VoiceOrder.activityList.get(VoiceOrder.activityList.size()-1).equals("WarnActivity")){
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    VoiceOrder.activityList.remove(VoiceOrder.activityList.size()-1);
                    finish();
                }
            });
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
